package net.zdreamer.geracomium.ui.more;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;

import com.example.geracomium.R;

import net.zdreamer.geracomium.adapter.DateGridAdapter;
import net.zdreamer.geracomium.entity.DateGirdInfos;
import net.zdreamer.geracomium.ui.BreakfastTabActivity;
import net.zdreamer.geracomium.ui.DinnerTabActivity;
import net.zdreamer.geracomium.ui.LunchTabActivity;

public class ReserveFoodActivity extends TabActivity implements OnClickListener {
    private View oneTab, towTab, threeTab;
    private GridView reserve_data;
    private DateGridAdapter madpter;
    private ImageView back, share, ordinglsit;
    private TextView title_content;
    private Intent intent;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_reserverfood);
        init();
        settab();
    }



    private void init() {
        back = (ImageView) findViewById(R.id.back);
        share = (ImageView) findViewById(R.id.share);
        title_content = (TextView) findViewById(R.id.title_content);
        ordinglsit = (ImageView) findViewById(R.id.ordinglsit);

        share.setImageResource(R.drawable.foodplan_selector);
        title_content.setText("膳食订餐");
        back.setOnClickListener(this);
        share.setOnClickListener(this);
        ordinglsit.setOnClickListener(this);

        reserve_data = (GridView) findViewById(R.id.reserve_data);

        DateGirdInfos date = new DateGirdInfos();
        madpter = new DateGridAdapter(ReserveFoodActivity.this,
                date.dategirdinfos, R.layout.date_gridview);
        reserve_data.setAdapter(madpter);
        reserve_data.setOnItemClickListener(madpter);
        oneTab = (View) LayoutInflater.from(this).inflate(
                R.layout.tab_breakfast, null);
        towTab = (View) LayoutInflater.from(this).inflate(
                R.layout.tab_lunchmeals, null);
        threeTab = (View) LayoutInflater.from(this).inflate(
                R.layout.tab_dinner, null);
    }

    private void settab() {
        TabHost tabHost = getTabHost();
        TabHost.TabSpec spec;
        Intent intent;

        intent = new Intent().setClass(this, BreakfastTabActivity.class);
        intent.putExtra("gridinfo", "serve");
        spec = tabHost.newTabSpec("breakfast").setIndicator(oneTab)
                .setContent(intent);
        tabHost.addTab(spec);
        intent = new Intent().setClass(this, LunchTabActivity.class);
        intent.putExtra("gridinfo", "serve");
        spec = tabHost.newTabSpec("lunchmeals").setIndicator(towTab)
                .setContent(intent);
        tabHost.addTab(spec);
        intent = new Intent().setClass(this, DinnerTabActivity.class);
        intent.putExtra("gridinfo", "serve");
        spec = tabHost.newTabSpec("dinner").setIndicator(threeTab)
                .setContent(intent);
        tabHost.addTab(spec);
        tabHost.setCurrentTab(0);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back:
                ReserveFoodActivity.this.finish();
                break;
            case R.id.share:
                intent = new Intent(ReserveFoodActivity.this, MealsPlanActivity.class);
                startActivity(intent);
                break;
            case R.id.ordinglsit:
                intent = new Intent(ReserveFoodActivity.this,
                        OrdingListActivity.class);
                startActivity(intent);
                break;
            default:
                break;
        }
    }

}
